package com.gaotu.ci.profile;

import com.gaotu.ci.access.AccessService;
import com.gaotu.ci.user.User;
import com.gaotu.ci.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProfileService {
    @Autowired
    private UserService userService;

    @Autowired
    private AccessService accessService;

    public Profile getAndAccessProfileByUserId(Long userId){
        User user = this.userService.getUserById(userId);
        if (user == null){
            return null;
        }

        Integer count = this.accessService.getAccessCountByUserId(userId);

        this.accessService.incAccessCount(1);

        Profile profile = new Profile();
        profile.setUserName(user.getName());
        profile.setAccessCount(count);
        return profile;
    }
}
